package com.zte.claa.inficombo.csa.app.model.app;

public class AppTarget {
	private String appAuthKey;
	private String appEUI;
	private String csifIpAddr;
	private int csifPort;
	private int appnonce;
	
	public AppTarget(){
		this.appnonce = (int)(Math.random()*10000);
	}

	public String getAppEUI() {
		return appEUI;
	}

	public void setAppEUI(String appEUI) {
		this.appEUI = appEUI;
	}

	public String getCsifIpAddr() {
		return csifIpAddr;
	}

	public void setCsifIpAddr(String csifIpAddr) {
		this.csifIpAddr = csifIpAddr;
	}

	public int getCsifPort() {
		return csifPort;
	}

	public void setCsifPort(int csifPort) {
		this.csifPort = csifPort;
	}

	public String getAppAuthKey() {
		return appAuthKey;
	}

	public void setAppAuthKey(String appAuthKey) {
		this.appAuthKey = appAuthKey;
	}

	/**
	 * 每次取值时，都将其+1，避免nonce重复导致注册失败.
	 * @return
	 */
	public int getAndIncAppnonce() {
		int nonce = ++this.appnonce;
		if(nonce >= Integer.MAX_VALUE){
			this.appnonce = (int)(Math.random()*10000);
			nonce = this.appnonce;
		}
		return nonce;
	}
	
	/**
	 * 
	 * @return
	 */
	public int getCurAppNonce(){
		return this.appnonce;
	}
	
	/**
	 * toString()
	 * 
	 */
	public String toString(){
		StringBuilder sb = new StringBuilder();
		sb.append("AppEUI=").append(this.appEUI).append(", ");
		sb.append("AppAuthKey=").append(this.appAuthKey).append(", ");
		sb.append("CSIFIp=").append(this.csifIpAddr).append(", ");
		sb.append("CSIFPort=").append(this.csifPort).append(", ");
		sb.append("Apponce=").append(this.appnonce).append(".");		
		return sb.toString();
	}
	
}
